﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tools
{
  public  class CommonHellper
    {
        //写到记事本
        public static void WriteLog(string msg)
        {

            string currentDirectory = Environment.CurrentDirectory;
            string sFileName = currentDirectory + @"\错误日志\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
            FileStream fs;
            StreamWriter sw;
            if (File.Exists(sFileName))
            //验证文件是否存在，有则追加，无则创建
            {
                fs = new FileStream(sFileName, FileMode.Append, FileAccess.Write);
            }
            else
            {
                string dir = Path.GetDirectoryName(sFileName);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                fs = new FileStream(sFileName, FileMode.Create, FileAccess.Write);
            }
            sw = new StreamWriter(fs);
            sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":\r\n" + msg);
            sw.Close();
            fs.Close();
        }
    }
}
